//
//  RecommendViewController.m
//  BabyAndBaby
//
//  Created by 范琦 on 16/7/27.
//  Copyright © 2016年 范琦. All rights reserved.
//

#import "RecommendViewController.h"
#import "recommendFirstView.h"
#import "recommendTopView.h"
#import "recommendSecondView.h"
#import "recommendThirdView.h"
#import "getDistrictModel.h"
#import "ASIFormDataRequest.h"
#import "ASINetworkQueue.h"
#import "MBProgressHUD.h"
#import "PhotoCollectionViewCell.h"
#import "TZImagePickerController.h"
@interface RecommendViewController ()<UIPickerViewDelegate, UIPickerViewDataSource, UICollectionViewDataSource, UICollectionViewDelegate, UIActionSheetDelegate,UIImagePickerControllerDelegate, ASIHTTPRequestDelegate>
{
    CGFloat _itemWH;
    CGFloat _margin;
    NSMutableArray *arr;
}
@property (nonatomic, strong) UIScrollView *bigScroll;
@property (nonatomic, strong) recommendFirstView *recommendFirst;
@property (nonatomic, strong) recommendTopView *recommendTop;
@property (nonatomic, strong) recommendSecondView *recommendSecond;
@property (nonatomic, strong) recommendThirdView *recommendThird;

@property (nonatomic, strong) UIPickerView *pickView;
@property (nonatomic, strong) UIView *pickTopView;
@property (nonatomic, strong) NSString *str;
@property (nonatomic, strong) NSMutableArray *listArr;
@property (nonatomic, strong) NSString *number;

/**
 *  存放图片的数组
 */
@property (nonatomic, strong) NSMutableArray *imageArray;

@property (nonatomic, strong) ASINetworkQueue *queue;

// 存放图片string数组
@property (nonatomic, strong) NSMutableArray *strArr;

/**
 *  拍照
 */
@property (nonatomic, strong)  UIImagePickerController *imagePicker;
@property (nonatomic ,strong) NSString *ImageStr;

@property (nonatomic, strong) MBProgressHUD *mbView;// 视图加载
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionView *secondCollectionView;
@property (nonatomic, strong) UICollectionView *thirdCollectionView;
@end

@implementation RecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor huiseColor];
    [self getNumberData];
    [self creatBigScrollView];
    [self creatrecommendTopView];
    [self creatFirstView];
    [self creatSecondView];
    [self creatThirdView];
    [self creatRightButton];
    _listArr = [NSMutableArray array];

    
}

- (void)getDistrictData
{
    if (_listArr.count == 0) {
        
        YTKNetHandle *api = [[YTKNetHandle alloc] initWithUrl:[NSString stringWithFormat:@"/Merchant/getMerchantArea.html?token=%@",TOKEN] RegisterApiMethod:RequestMethodGet];
        [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
            NSArray *arr = [request.responseBody objectForKey:@"result"];
            NSLog(@"%@", arr);
            for (NSDictionary *dic in arr) {
                getDistrictModel *model = [[getDistrictModel alloc] init];
                model.area_id = [dic objectForKey:@"area_id"];
                model.name = [dic objectForKey:@"name"];
                [self.listArr addObject:model];
                [_pickView reloadAllComponents];
            }
        } failure:^(YTKBaseRequest *request) {
            
        }];
    }
}

- (void)getNumberData
{
    YTKNetHandle *api = [[YTKNetHandle alloc] initWithUrl:[NSString stringWithFormat:@"/Merchant/getNumber?token=%@",TOKEN] RegisterApiMethod:RequestMethodGet];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *dic = [request.responseBody objectForKey:@"result"];
        NSLog(@"%@", dic);
        _number = [dic objectForKey:@"number"];
        NSLog(@"%@",_number);
        _recommendFirst.MerchantCodeTextfield.text = [NSString stringWithFormat:@"商户编号：%@", _number];

    } failure:^(YTKBaseRequest *request) {
        
    }];

}

- (NSMutableArray *)imageArray
{
    if (!_imageArray) {
        _imageArray = [NSMutableArray array];
    }
    return _imageArray;
}

- (UIImagePickerController *)imagePicker
{
    if (!_imagePicker) {
        _imagePicker = [[UIImagePickerController alloc]init];
        _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; //设置image picker的来源,这里设置为摄像头
        _imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
        _imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
        _imagePicker.allowsEditing = YES; // 允许编辑
        _imagePicker.delegate = self; // 设置代理。检测操作
    }
    return _imagePicker;
    
}

#pragma mark UICollectionViewDatasource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (self.imageArray.count >= 9) {
        return self.imageArray.count;
    }else{
        return self.imageArray.count + 1;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (collectionView == _collectionView) {
        
        PhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCollectionViewCell" forIndexPath:indexPath];
        if (indexPath.row == self.imageArray.count) {
            cell.delegateBtn.hidden = YES;
            cell.imageView.image = [UIImage imageNamed:@"添加图片"];
        } else {
            cell.delegateBtn.hidden = NO;
            cell.delegateBtn.tag = indexPath.row;
            [cell.delegateBtn addTarget:self action:@selector(delegateImage:) forControlEvents:UIControlEventTouchUpInside];
            cell.imageView.image = self.imageArray[indexPath.row];
        }
        return cell;
    } else if (collectionView == _secondCollectionView) {
        PhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCollectionViewCell" forIndexPath:indexPath];
        if (indexPath.row == self.imageArray.count) {
            cell.delegateBtn.hidden = YES;
            cell.imageView.image = [UIImage imageNamed:@"添加图片"];
        } else {
            cell.delegateBtn.hidden = NO;
            cell.delegateBtn.tag = indexPath.row;
            [cell.delegateBtn addTarget:self action:@selector(delegateImage:) forControlEvents:UIControlEventTouchUpInside];
            cell.imageView.image = self.imageArray[indexPath.row];
        }
        return cell;
    } else {
        PhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCollectionViewCell" forIndexPath:indexPath];
        if (indexPath.row == self.imageArray.count) {
            cell.delegateBtn.hidden = YES;
            cell.imageView.image = [UIImage imageNamed:@"添加图片"];
        } else {
            cell.delegateBtn.hidden = NO;
            cell.delegateBtn.tag = indexPath.row;
            [cell.delegateBtn addTarget:self action:@selector(delegateImage:) forControlEvents:UIControlEventTouchUpInside];
            cell.imageView.image = self.imageArray[indexPath.row];
        }
        return cell;
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (collectionView == _collectionView) {
        
        if (indexPath.row == self.imageArray.count)
        {
            //        [self takePhotoOrSelectAlbum];
        }else{
            //这里点击图片看大图
        }
    } else if (collectionView == _secondCollectionView) {
        if (indexPath.row == self.imageArray.count)
        {
            //        [self takePhotoOrSelectAlbum];
        }else{
            
        }
    } else {
        if (indexPath.row == self.imageArray.count)
        {
            //        [self takePhotoOrSelectAlbum];
        }else{
            
        }
    }
}

//删除图片
- (void)delegateImage:(UIButton *)sender
{
    [self.imageArray removeObjectAtIndex:sender.tag];
//    [self collectionHeight];
//    [self viewHeight];
//    [self tableViewHeight];
//    [self changeScrollViewContentSize];
    [_collectionView reloadData];
}

//选择拍照还是从相册选择
- (void)takePhotoOrSelectAlbum
{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从手机相册选择", nil];
    [sheet showInView:self.view];
}

#pragma mark -UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {
        case 0:
        {
            [self presentViewController:self.imagePicker animated:YES completion:nil];
        }
            break;
        case 1:
        {
            // 打开相册
            TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:3 delegate:self];
            imagePickerVc.maxImagesCount = 9 - self.imageArray.count;
            imagePickerVc.navigationBar.barTintColor = [UIColor redColor]; //相册选择器的导航栏的颜色
            imagePickerVc.oKButtonTitleColorDisabled = [UIColor redColor]; //选择照片时文字的颜色
            imagePickerVc.oKButtonTitleColorNormal = [UIColor greenColor]; //没有选择照片时文字的颜色
            imagePickerVc.allowPickingVideo = NO;
            // You can get the photos by block, the same as by delegate.
            // 你可以通过block或者代理，来得到用户选择的照片.
            [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets) {
                
                
                
            }];
            [self presentViewController:imagePickerVc animated:YES completion:nil];
            
        }
            break;
        default:
            break;
    }
}

#pragma mark - UIImagePickerController代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    UIImage *image;
    //如果允许编辑则获得编辑后的照片，否则获取原始照片
    if (self.imagePicker.allowsEditing) {
        image = [info objectForKey:UIImagePickerControllerEditedImage];//获取编辑后的图片
    }else{
        image = [info objectForKey:UIImagePickerControllerOriginalImage]; //获取原始照片
    }
    NSData *data = UIImageJPEGRepresentation(image, 1.0f);
    [arr addObject:data];
    [self shangchuan];
    
    [self.imageArray addObject:image];
//    [self collectionHeight];
//    [self viewHeight];
//    [self tableViewHeight];
//    [self changeScrollViewContentSize];
    [_collectionView reloadData];
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark TZImagePickerControllerDelegate
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets{
    
    // 把选中的图片转成NSData类型(缩略图)
    for (UIImage *image in photos) {
        
        NSData *data = UIImageJPEGRepresentation(image, 1.0f);
        [arr addObject:data];
    }
    
    [self shangchuan];
    //
    //        // 把选中的图片转成NSData类型(全屏图)
    //    NSData *data1 = UIImageJPEGRepresentation([UIImage imageWithCGImage:[[[assets objectAtIndex:0] defaultRepresentation] fullScreenImage]], 0);    [self.imageArray addObjectsFromArray:photos];
    [self.imageArray addObjectsFromArray:photos];
    NSLog(@"%ld", self.imageArray.count);
    
//    [self collectionHeight];
//    [self viewHeight];
//    [self tableViewHeight];
//    [self changeScrollViewContentSize];
    [_collectionView reloadData];
    //    _collectionView.contentSize = CGSizeMake(0, ((self.imageArray.count + 2) / 3 ) * (_margin + _itemWH));
}



- (void)shangchuan{
    //       上传地址
    //    NSURL *url = [NSURL URLWithString:@"http://qyjjlb.dev.hsydev.com/api.php/Public/imgsUpload.html"];
    self.mbView = [[MBProgressHUD alloc] initWithView:self.view];
    self.mbView.labelText = @"正在上传";
    [self.mbView setMode:MBProgressHUDModeIndeterminate];
    [self.mbView show:YES];
    [self.view addSubview:self.mbView];
    NSString *urlStr = @"http://bzbv3.dev.hsydev.com/tui.php/Base/imgsUpload.html";
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    // 数据类型data
    //    [request setPostFormat:ASIMultipartFormDataPostFormat];
    
    for (int i = 0; i < arr.count; i++) {
        [request addData:arr[i] withFileName:[NSString stringWithFormat:@"name%d.jpeg",i] andContentType:@"image/jpeg" forKey:[NSString stringWithFormat:@"namee%d",i]];
        
    }
    if (!self.queue) {
        self.queue = [[ASINetworkQueue alloc] init];
        self.queue.maxConcurrentOperationCount = 1;
    }
    [request setDelegate:self];
    
    [request setDidFinishSelector:@selector(requestDone:)];
    [request setDidFailSelector:@selector(requestWentWrong:)];
    [self.queue addOperation:request];
    [self.queue go];
    
}

- (void)requestDone:(ASIFormDataRequest *)request
{
    NSData *data = [request responseData];
    id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    _strArr = [result objectForKey:@"result"];
    NSLog(@"%@", data);
    [self.mbView removeFromSuperview];
}
- (void)requestWentWrong:(ASIFormDataRequest *)request
{
    
    
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
{
    NSLog(@"完成");
}


- (void)creatRightButton
{
    
    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    shareButton.frame = CGRectMake(0, 0, 50, 30);
    [shareButton setTitle:@"上传" forState:UIControlStateNormal];
    shareButton.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [[shareButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        NSLog(@"点击");
    }];
    UIBarButtonItem *barButtonItem1 = [[UIBarButtonItem alloc]initWithCustomView:shareButton];
    self.navigationItem.rightBarButtonItems = @[barButtonItem1];
    
}

#warning 创建PickerView
- (void)creatPickerView:(UIButton *)btn
{
    if (_pickView == nil) {
        
        self.pickView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, KSCREENHEIGHT - 150, KSCREENWIDTH, 150)];
        _pickView.frame = CGRectMake(0, KSCREENHEIGHT - 144, KSCREENWIDTH, 144);
        _pickView.delegate = self;
        _pickView.dataSource = self;
        [self.view addSubview:_pickView];
        _pickView.backgroundColor = [UIColor huiseColor];
        
        self.pickTopView = [[UIView alloc]initWithFrame:CGRectMake(0, _pickView.frame.origin.y - 30, KSCREENWIDTH, 30)];
        [self.view addSubview:_pickTopView];
        _pickTopView.backgroundColor = HUIBACKGROUNDCOLOR;
        
    }else{
        [self.view addSubview:_pickView];
        [self.view addSubview:_pickTopView];
    }
    UIButton *done = [UIButton buttonWithType:UIButtonTypeSystem];
    [done setTitle:@"Done" forState:UIControlStateNormal];
    done.frame = CGRectMake(KSCREENWIDTH - 60, 0, 40, 30);
    done.tintColor = [UIColor blackColor];
    [_pickTopView addSubview:done];
    [[done rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        [_pickView removeFromSuperview];
        [_pickTopView removeFromSuperview];
 
        _recommendTop.districtLabel.text = _str;
    }];
    
}
#warning PickerView代理方法
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    
    return _listArr.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    getDistrictModel *model =_listArr[row];
    _str = model.name;
    NSLog(@"%@", _str);
    return _str;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

    getDistrictModel *model =_listArr[row];
    _str = model.name;
    
}

- (void)creatBigScrollView
{
    _bigScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, KSCREENHEIGHT)];
    _bigScroll.backgroundColor = [UIColor huiseColor];
    _bigScroll.contentSize = CGSizeMake(0, KSCREENHEIGHT * 2);
    [self.view addSubview:_bigScroll];
}

- (void)creatrecommendTopView
{
    self.recommendTop = [[[NSBundle mainBundle] loadNibNamed:@"recommendTopView" owner:nil options:nil] lastObject];
    _recommendTop.frame = CGRectMake(0, 0, KSCREENWIDTH, 33 * KSCREENHEIGHT / 667);
    [[_recommendTop.bigButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        [self getDistrictData];
        [self creatPickerView:_recommendTop.bigButton];
    }];
    
    [_bigScroll addSubview:_recommendTop];
}

- (void)creatFirstView
{
    self.recommendFirst = [[[NSBundle mainBundle] loadNibNamed:@"recommendFirstView" owner:nil options:nil] lastObject];
    _recommendFirst.frame = CGRectMake(0, 49 * KSCREENHEIGHT / 667, KSCREENWIDTH, 340 * KSCREENHEIGHT / 667);
    _recommendFirst.BasicInformationLabel.textColor = [UIColor colorWithRed:76 / 255.0 green:217 / 255.0 blue:192 / 255.0 alpha:1];
//    _recommendFirst.MerchantCodeTextfield.text = [NSString stringWithFormat:@"商户编号：%@", _number];
    [[_recommendFirst.MerchantCodeTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendFirst.MerchantCodeTextfield.text;
        _recommendFirst.MerchantCodeTextfield.text = [NSString stringWithFormat:@"商户编号：%@",textStr];
    }];
    [[_recommendFirst.MerchantCodeTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendFirst.MerchantCodeTextfield.text componentsSeparatedByString:@"："];
        _recommendFirst.MerchantCodeTextfield.text = arr1[1];
    }];
    
    [[_recommendFirst.MerchantNameTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendFirst.MerchantNameTextfield.text;
        _recommendFirst.MerchantNameTextfield.text = [NSString stringWithFormat:@"商户名称：%@",textStr];
    }];
    [[_recommendFirst.MerchantNameTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendFirst.MerchantNameTextfield.text componentsSeparatedByString:@"："];
        _recommendFirst.MerchantNameTextfield.text = arr1[1];
    }];
    
    [[_recommendFirst.ContactTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendFirst.ContactTextfield.text;
        _recommendFirst.ContactTextfield.text = [NSString stringWithFormat:@"联系人：%@",textStr];
    }];
    [[_recommendFirst.ContactTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendFirst.ContactTextfield.text componentsSeparatedByString:@"："];
        _recommendFirst.ContactTextfield.text = arr1[1];
    }];
    
    [[_recommendFirst.PhoneNumberTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendFirst.PhoneNumberTextfield.text;
        _recommendFirst.PhoneNumberTextfield.text = [NSString stringWithFormat:@"登录账号（手机号）：%@",textStr];
    }];
    [[_recommendFirst.PhoneNumberTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendFirst.PhoneNumberTextfield.text componentsSeparatedByString:@"："];
        _recommendFirst.PhoneNumberTextfield.text = arr1[1];
    }];
    
    [[_recommendFirst.DetailAddressTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendFirst.DetailAddressTextfield.text;
        _recommendFirst.DetailAddressTextfield.text = [NSString stringWithFormat:@"详细地址：%@",textStr];
    }];
    [[_recommendFirst.DetailAddressTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendFirst.DetailAddressTextfield.text componentsSeparatedByString:@"："];
        _recommendFirst.DetailAddressTextfield.text = arr1[1];
    }];
    [_bigScroll addSubview:_recommendFirst];
}

- (void)creatSecondView
{
    self.recommendSecond = [[[NSBundle mainBundle] loadNibNamed:@"recommendSecondView" owner:nil options:nil] lastObject];
    _recommendSecond.frame = CGRectMake(0, 403 * KSCREENHEIGHT / 667, KSCREENWIDTH, 397 * KSCREENHEIGHT / 667);
    _recommendSecond.VerificationinformationLabel.textColor = [UIColor colorWithRed:76 / 255.0 green:217 / 255.0 blue:192 / 255.0 alpha:1];
    [[_recommendSecond.ShopkeeperNameTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendSecond.ShopkeeperNameTextfield.text;
        _recommendSecond.ShopkeeperNameTextfield.text = [NSString stringWithFormat:@"店主姓名：%@",textStr];
    }];
    [[_recommendSecond.ShopkeeperNameTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendSecond.ShopkeeperNameTextfield.text componentsSeparatedByString:@"："];
        _recommendSecond.ShopkeeperNameTextfield.text = arr1[1];
    }];
    
    [[_recommendSecond.ShopkeeperPhoneTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendSecond.ShopkeeperPhoneTextfield.text;
        _recommendSecond.ShopkeeperPhoneTextfield.text = [NSString stringWithFormat:@"店主电话：%@",textStr];
    }];
    [[_recommendSecond.ShopkeeperPhoneTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendSecond.ShopkeeperPhoneTextfield.text componentsSeparatedByString:@"："];
        _recommendSecond.ShopkeeperPhoneTextfield.text = arr1[1];
    }];
    
    [[_recommendSecond.IDNumbertextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendSecond.IDNumbertextfield.text;
        _recommendSecond.IDNumbertextfield.text = [NSString stringWithFormat:@"身份证号：%@",textStr];
    }];
    [[_recommendSecond.IDNumbertextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendSecond.IDNumbertextfield.text componentsSeparatedByString:@"："];
        _recommendSecond.IDNumbertextfield.text = arr1[1];
    }];
    // textfield不可编辑
    _recommendSecond.PaperUploadtextfield.enabled = NO;
    _recommendSecond.BusinessLicensetextfield.enabled = NO;
    _recommendSecond.ShopEnvironmenttextfield.enabled = NO;
    
    [[_recommendSecond.firstButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        [self takePhotoOrSelectAlbum];
    }];
    [[_recommendSecond.secondButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        [self takePhotoOrSelectAlbum];
    }];
    [[_recommendSecond.thirdButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        [self takePhotoOrSelectAlbum];
    }];
    // 照片加载
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    _margin = 4;
    _itemWH = (357 - 2 * _margin - 4) / 3 - _margin;
    layout.itemSize = CGSizeMake(100 * KSCREENWIDTH / 375, 100 * KSCREENHEIGHT / 667);
    layout.minimumInteritemSpacing = _margin;
    layout.minimumLineSpacing = _margin;
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(20 * KSCREENWIDTH / 375, _recommendSecond.PaperUploadtextfield.frame.origin.y + _recommendSecond.PaperUploadtextfield.frame.size.height + 32, 320 * KSCREENWIDTH / 375, 0) collectionViewLayout:layout];
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.contentInset = UIEdgeInsetsMake(4 * KSCREENWIDTH / 375, 0, 0, 2 * KSCREENHEIGHT / 667);
    _collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -2 * KSCREENHEIGHT / 667);
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    [_recommendSecond addSubview:_collectionView];
    [_collectionView registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"PhotoCollectionViewCell"];
    
    UICollectionViewFlowLayout *layout1 = [[UICollectionViewFlowLayout alloc] init];
    _margin = 4;
    _itemWH = (357 - 2 * _margin - 4) / 3 - _margin;
    layout.itemSize = CGSizeMake(100 * KSCREENWIDTH / 375, 100 * KSCREENHEIGHT / 667);
    layout.minimumInteritemSpacing = _margin;
    layout.minimumLineSpacing = _margin;
    _secondCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(20 * KSCREENWIDTH / 375, _recommendSecond.BusinessLicensetextfield.frame.origin.y + _recommendSecond.BusinessLicensetextfield.frame.size.height + 32, 320 * KSCREENWIDTH / 375, 0) collectionViewLayout:layout1];
    _secondCollectionView.backgroundColor = [UIColor whiteColor];
    _secondCollectionView.contentInset = UIEdgeInsetsMake(4 * KSCREENWIDTH / 375, 0, 0, 2 * KSCREENHEIGHT / 667);
    _secondCollectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -2 * KSCREENHEIGHT / 667);
    _secondCollectionView.dataSource = self;
    _secondCollectionView.delegate = self;
    [_recommendSecond addSubview:_secondCollectionView];
    [_secondCollectionView registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"PhotoCollectionViewCell"];
    
    UICollectionViewFlowLayout *layout2 = [[UICollectionViewFlowLayout alloc] init];
    _margin = 4;
    _itemWH = (357 - 2 * _margin - 4) / 3 - _margin;
    layout.itemSize = CGSizeMake(100 * KSCREENWIDTH / 375, 100 * KSCREENHEIGHT / 667);
    layout.minimumInteritemSpacing = _margin;
    layout.minimumLineSpacing = _margin;
    _thirdCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(20 * KSCREENWIDTH / 375, _recommendSecond.ShopEnvironmenttextfield.frame.origin.y + _recommendSecond.ShopEnvironmenttextfield.frame.size.height + 32, 320 * KSCREENWIDTH / 375, 0) collectionViewLayout:layout2];
    _thirdCollectionView.backgroundColor = [UIColor whiteColor];
    _thirdCollectionView.contentInset = UIEdgeInsetsMake(4 * KSCREENWIDTH / 375, 0, 0, 2 * KSCREENHEIGHT / 667);
    _thirdCollectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -2 * KSCREENHEIGHT / 667);
    _thirdCollectionView.dataSource = self;
    _thirdCollectionView.delegate = self;
    [_recommendSecond addSubview:_thirdCollectionView];
    [_thirdCollectionView registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"PhotoCollectionViewCell"];
    
    [_bigScroll addSubview:_recommendSecond];
}

- (void)creatThirdView
{
    self.recommendThird = [[[NSBundle mainBundle] loadNibNamed:@"recommendThirdView" owner:nil options:nil] lastObject];
    _recommendThird.frame = CGRectMake(0, 815 * KSCREENHEIGHT / 667, KSCREENWIDTH, 224 * KSCREENHEIGHT / 667);
    _recommendThird.AcconutInformationLabel.textColor = BACKGROUNDCOLOR;
    
    [[_recommendThird.BankNameTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendThird.BankNameTextfield.text;
        _recommendThird.BankNameTextfield.text = [NSString stringWithFormat:@"开户银行：%@",textStr];
    }];
    [[_recommendThird.BankNameTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendThird.BankNameTextfield.text componentsSeparatedByString:@"："];
        _recommendThird.BankNameTextfield.text = arr1[1];
    }];
    
    [[_recommendThird.BankNumberTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendThird.BankNumberTextfield.text;
        _recommendThird.BankNumberTextfield.text = [NSString stringWithFormat:@"银行卡号：%@",textStr];
    }];
    [[_recommendThird.BankNumberTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendThird.BankNumberTextfield.text componentsSeparatedByString:@"："];
        _recommendThird.BankNumberTextfield.text = arr1[1];
    }];
    

    [[_recommendThird.PersonNameTextfield rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
        NSString *textStr = _recommendThird.PersonNameTextfield.text;
        _recommendThird.PersonNameTextfield.text = [NSString stringWithFormat:@"开户人姓名：%@",textStr];
    }];
    [[_recommendThird.PersonNameTextfield rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(id x) {
        NSArray *arr1 = [_recommendThird.PersonNameTextfield.text componentsSeparatedByString:@"："];
        _recommendThird.PersonNameTextfield.text = arr1[1];
    }];

    [_bigScroll addSubview:_recommendThird];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
